import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
]

export const allAsyncRoutes = [
  // {
  //   path: "/acl",
  //   component: Layout,
  //   name: "Acl",
  //   meta: { title: "权限管理", icon: 'el-icon-lock' },
  //   children: [
  //     {
  //       path: "user/list",
  //       component: () => import("@/views/acl/user/list"),
  //       name: "User",
  //       meta: {title: "用户"},
  //     },
      
  //   ]
  // },
  {
    path: "/product",
    component: Layout,
    name: "Product",
    meta: { title: "商品管理", icon: "el-icon-s-goods" },
    children: [
      {
        path: "tmManage",
        component: () => import("@/views/product/tmManage/index"),
        name: "Trademark",
        meta: { title: "品牌管理" }
      },
      {
        path: "attrManage",
        component: () => import("@/views/product/attrManage/index"),
        name: "Attr",
        meta: { title: "平台属性管理" }
      },
      {
        path: "spuManage",
        component: () => import("@/views/product/spuManage/index"),
        name: "Spu",
        meta: { title: "Spu管理" }
      },
      {
        path: "skuManage",
        component: () => import("@/views/product/skuManage/index"),
        name: "Sku",
        meta: { title: "Sku管理" }
      },
    ]
  },
  {
    path: "/test",
    component: Layout,
    name: "Test",
    meta: { title: "测试", icon: "el-icon-s-goods" },
    children: [
      {
        path: "test111",
        component: () => import("@/views/test/test111/index"),
        name: "Test111",
        meta: { title: "测试1" },
      },
      {
        path: "test222",
        component: () => import("@/views/test/test222/index"),
        name: "Test222",
        meta: { title: "测试2" }
      }
    ]
  },
]

// 404 page must be placed at the end !!!
export const anyRoute = { path: '*', redirect: '/404', hidden: true }

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
